package com.jy.wms.common.base;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SpringUtil;
import com.jy.wms.dao.WmsEstimatedArrivalOrderDetailedMapper;
import com.jy.wms.pojo.SysHz;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 预期到货通知单的导入
 *  Created by syh on 2018/9/13.
 */
public class WmsEstimatedImportHanlder extends ExcelDataHandlerDefaultImpl {
    WmsEstimatedArrivalOrderDetailedMapper wmsEstimatedArrivalOrderMapper = SpringUtil.getBean(WmsEstimatedArrivalOrderDetailedMapper.class);
    private static Logger log = LoggerFactory.getLogger(WmsEstimatedArrivalOrderDetailedMapper.class);
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        System.out.print("value:" + value);
        log.info("value:" + value);
        /*if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);
        }*/
        if(originKey!="" && originKey!=null){
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }



    }

    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }

        System.out.println("originKey:" + originKey);
        log.info("originKey:" + originKey);
        if (originKey.equals("物料编码")) {
            return "hpbh";
        }
        if (originKey.equals("物料名称")) {
            return "hpmc";
        }
        if (originKey.equals("规格型号")) {
            return "gg";
        }

        if (originKey.equals("批次")) {
            return "hppc";
        }
        if (originKey.equals("生产日期")) {
            return "scrq";
        }
        if (originKey.equals("到期日期")) {
            return "sxrq";
        }

        if (originKey.equals("数量")) {
            return "yqsl";
        }

        if (originKey.equals("调拨单单号")) {
            return "asnbh";
        }
        if (originKey.equals("备注")) {
            return "bz";
        }
        return "";
    }
}